home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ch1 / pushme.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.3 KB  |  82 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. ////////////////////////////////////////////////////////
  22. // pushme.C, Using callback functions in C++
  23. ////////////////////////////////////////////////////////
  24. #include <stdlib.h>  // Needed for exit prototype
  25. #include <Xm/Xm.h>
  26. #include <Xm/PushB.h>
  27.  
  28. static void quitCallback ( Widget, XtPointer, XtPointer );
  29.  
  30. #if (XlibSpecificationRelease>=5)
  31. void main ( int argc, char **argv )
  32. #else
  33. void main ( unsigned int argc, char **argv )
  34. #endif
  35. {
  36.     Widget       button, toplevel;
  37.     XtAppContext app;
  38.     XmString     xmstr;
  39.     
  40.     // Initialize the Intrinsics
  41.     
  42.     toplevel = XtAppInitialize ( &app, "Pushme", NULL, 0, 
  43.                 &argc, argv, NULL, NULL, 0 );
  44.     
  45.     // Create a compound string 
  46.     
  47.     xmstr = XmStringCreateSimple ( "Push Me" );
  48.     
  49.     // Create an XmPushButton widget to display the string
  50.     
  51.     button = XtVaCreateManagedWidget ( "button",
  52.                       xmPushButtonWidgetClass,
  53.                       toplevel,
  54.                       XmNlabelString, xmstr, 
  55.                       NULL );
  56.     
  57.     // Free the compound string after the XmPushButton has copied it.
  58.     
  59.     XmStringFree ( xmstr );
  60.     
  61.     // Register the quitCallback callback function
  62.     // to be called when the button is pushed
  63.     
  64.     XtAddCallback ( button, 
  65.            XmNactivateCallback, 
  66.            quitCallback, 
  67.            NULL ); // No client data needed
  68.     
  69.     // Realize all widgets and enter the main event loop
  70.     
  71.     XtRealizeWidget ( toplevel );
  72.     XtAppMainLoop ( app );
  73. }
  74.  
  75. // Callback invoked when button is activated
  76.  
  77. void quitCallback ( Widget w, XtPointer, XtPointer )
  78. {
  79.     exit ( 0 );
  80.  
  81.